// ArchiveCommandLine.h

#ifndef __ARCHIVE_COMMAND_LINE_H
#define __ARCHIVE_COMMAND_LINE_H

#include "CommandLineParser.h"
#include "Common/FileSystem/Wildcard.h"

#include "Common/Archive/Extract.h"
#include "Common/Archive/Update.h"

#include <vector>

namespace GUI
{
namespace App
{

	using namespace Common;
struct CArchiveCommandLineException: public CString
{
  CArchiveCommandLineException(LPCTSTR errorMessage): CString(errorMessage) {}
};

	enum class CommandType 
	{
	  kAdd = 0,
	  kUpdate,
	  kDelete,
	  kTest,
	  kExtract,
	  kFullExtract,
	  kList,
	  kBenchmark,
	  kInfo
	};

	enum class RecursedType 
	{
	  kRecursed,
	  kWildCardOnlyRecursed,
	  kNonRecursed
	};


struct CArchiveCommand
{
  CommandType CommandType;
  bool IsFromExtractGroup() const;
  bool IsFromUpdateGroup() const;
  bool IsTestMode() const { return CommandType == CommandType::kTest; }
  Common::Archive::Extract::PathMode GetPathMode() const;
};

struct CArchiveCommandLineOptions
{
  bool HelpMode;

  #ifdef _WIN32
  bool LargePages;
  #endif

  bool IsInTerminal;
  bool IsStdOutTerminal;
  bool IsStdErrTerminal;
  bool StdInMode;
  bool StdOutMode;
  bool EnableHeaders;

  bool YesToAll;
  bool ShowDialog;
  // Wildcard::CCensor ArchiveWildcardCensor;
  Common::FileSystem::Wildcard::CCensor WildcardCensor;

  CArchiveCommand Command;
  CString ArchiveName;

  #ifndef _NO_CRYPTO
  bool PasswordEnabled;
  CString Password;
  #endif

  bool TechMode;
  // Extract
  bool CalcCrc;
  bool AppendName;
  CString OutputDir;
  Common::Archive::Extract::OverwriteMode OverwriteMode;
  std::vector<CString> ArchivePathsSorted;
  std::vector<CString> ArchivePathsFullSorted;
  std::vector<Props::CProperty> ExtractProperties;

  Archive::CUpdateOptions UpdateOptions;
  CString ArcType;
  bool EnablePercents;

  // Benchmark
  UINT32 NumIterations;
  UINT32 NumThreads;
  UINT32 DictionarySize;
  CString Method;


  CArchiveCommandLineOptions(): StdInMode(false), StdOutMode(false) {};
};

class CArchiveCommandLineParser
{
  App::CCmdLineParser parser;
public:
  CArchiveCommandLineParser();
  void Parse1(const CStringVector &commandStrings, CArchiveCommandLineOptions &options);
  void Parse2(CArchiveCommandLineOptions &options);
};

void EnumerateDirItemsAndSort(Common::FileSystem::Wildcard::CCensor &wildcardCensor,
								std::vector<CString> &sortedPaths,
								std::vector<CString> &sortedFullPaths);

}

}
#endif
